package edu.online.controller;

import edu.online.object.UserObject;
import edu.online.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    private UserService userService;

    @Autowired
    public void setUserService (UserService userService) {
        this.userService = userService;
    }

    @ResponseBody
    @RequestMapping("/add")
    boolean add(@RequestBody UserObject userObject){
        return userService.Add(userObject);
    }

    @ResponseBody
    @RequestMapping("/list")
    List<UserObject> selectAll(@RequestParam(required = false) String userid){
        System.out.println("----------------------");
        if(userid != null)
            return userService.selectByUserid(userid);
        else
            return userService.selectALL();
    }

}
